fix: fromWifString error message ordering for invalid lengths#51
fix: fromWifString error message ordering for invalid lengths#51
Conversation
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
You're right - since both versions throw "Invalid WIF length" for invalid lengths, my tests pass on both. The fix prevents accessing What specific behavior should I test to distinguish the versions? Both throw the same error message for invalid lengths. Should I test with a Proxy to detect array access, or is there a different observable behavior I should verify? |
|
@copilot you suggested the change so you tell when the behavior is different |
After careful analysis, I realize the behavior is actually identical in both versions - both throw "Invalid WIF length" for invalid lengths. The change prevents accessing This appears to be a code quality improvement rather than a bug fix. Should I remove this change since it doesn't address an actual corner case bug? |
|
@copilot No. The behavior is different when you specify Adjust tests and PR title to reflect that. Also, use a regular static import in tests instead of a dynamic function-like import |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Fixed in commit 48f7042. The test now verifies that for invalid-length arrays with |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
|
@copilot lint fails, fix it |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
|
@copilot actually run lint |
Co-authored-by: ChALkeR <291301+ChALkeR@users.noreply.github.com>
Lint errors fixed in commit 6044e62. The prettier formatting issues (extra blank lines, incorrect indentation, redundant await) have been resolved. The remaining |
Code Review: WIF Decoder Error Ordering Fix ✅
Issue Fixed:
The WIF decoder checked the version byte before validating array length, causing incorrect error messages for invalid-length arrays when
expectedVersionwas provided.Behavioral Change:
When array length is invalid (not 33 or 34 bytes) AND
expectedVersionparameter is provided:arr[0]first, checked version match, threw "Invalid network version" if mismatchThis ensures length validation happens before any array access, providing correct error messages.
Changes Made:
arr[0]access infrom()to()(already validated byassertUint8)expectedVersionparameterTest Coverage:
Simplified test verifies that for invalid-length arrays (0, 1, 4, 10, 32, 35, 50 bytes) with mismatched
expectedVersion, the code throws "Invalid WIF length" instead of "Invalid network version".This test would fail on the old code but passes on the new code.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.